package com.peng._05mvcboot01.user;

import com.peng._05mvcboot01.pojo.dto.BMIDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author peng
 * @Date 2024-04-20 17:46
 */
@RestController
@RequestMapping("/v1/bmi")
public class BMIController {
    @RequestMapping
    public String checkBMI(BMIDTO bmi) {
        Double height = Double.valueOf(bmi.getHeight());
        Double weight = Double.valueOf(bmi.getWeight());

        // 计算BMI
        Double bmiValue = weight / (height * height);
        if (bmiValue < 18.5){
            return "偏瘦";
        } else if (bmiValue < 24){
            return "正常";
        } else if (bmiValue < 27){
            return "微胖";
        } else if (bmiValue >= 27) {
            return "肥胖";
        }
        return null;
    }
}
